# -*- coding: utf-8 -*-
# mysql数据库

# 安装驱动
# pip install mysql-connector

import mysql.connector

# 链接
conn = mysql.connector.connect(user='root',password='123456',database='test')

cursor = conn.cursor()

# 创建user表
cursor.execute('drop table user')
cursor.execute('create table user(id varchar(20) primary key,name varchar(20))')
cursor.execute('insert into user(id,name) values(\'1\',\'Michael\')')

print(cursor.rowcount)

# 提交事务
conn.commit()
cursor.close()

# 运行查询
cursor = conn.cursor()
cursor.execute('select * from user where id = %s',('1',))
print(cursor.fetchall())

# 关闭
cursor.close()
conn.close()